package com.changgou.goods.controller;

import com.changgou.goods.pojo.Sku;
import com.changgou.goods.pojo.Spec;
import com.changgou.goods.service.SkuService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
@CrossOrigin
public class SkuController {

    @Autowired
    private SkuService skuService;

    @GetMapping
    public Map search(@RequestParam(required = false) Map searchMap) {
        Map map = skuService.search(searchMap);
        return map;
    }

    @PostMapping(value = "/sku")
    public Result<List<Sku>> findList(@RequestBody(required = false) Sku sku) {
        List<Sku> skuList = skuService.findList(sku);
        return new Result<List<Sku>>(true, StatusCode.OK, "查询成功", skuList);
    }
    /***
     * 库存递减
     * @param username
     * @return
     */
    @PostMapping(value = "/decr/count")
    public Result decrCount(String username){
        //库存递减
        skuService.decrCount(username);
        return new Result(true,StatusCode.OK,"库存递减成功！");
    }
}
